package db10;

import java.util.HashSet;
import java.util.Random;
import java.util.Scanner;
import java.util.Set;

public class DoubleColor {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一会蓝球（范围1-6）：");
        int userBlueBall = scanner.nextInt();
        while (userBlueBall<1 || userBlueBall >6){
            System.out.println("蓝球输入错误，请重新输入（范围1-6）：");
            userBlueBall = scanner.nextInt();
        }

        Set<Integer> userRedBall = new HashSet<>();
        System.out.println("请输入6个红球（范围1-33）：");
        for (int i = 0; i <6 ; i++) {
            int redBall = scanner.nextInt();
            while (redBall<1 || redBall>33){
                redBall = scanner.nextInt();
            }
            userRedBall.add(redBall);
        }
        Random random = new Random();
        int systemBlueBall = random.nextInt(6)+1;
        Set<Integer> systemRedBalls = new HashSet<>();
        while (systemRedBalls.size()<6){
            int redBall = random.nextInt(33)+1;
            systemRedBalls.add(redBall);
        }
        int blueMatch = (userBlueBall == systemBlueBall) ? 1:0;
        int redMatch = 0;
        for (int redBall : userRedBall){
            if (systemRedBalls.contains(redBall)){
                redMatch++;
            }
        }
        System.out.println("您中了"+blueMatch+"个蓝球和"+redMatch+"个红球");
        scanner.close();
    }
}
